use apikit::*;
use bytes::Bytes;
use serde::{Deserialize, Serialize};
use validator::Validator;
use validator::impls::*;

#[derive(Debug, ApiModel, Serialize, Deserialize, Validator)]
pub struct ResponseBody<T> {
    #[validate(constant("0"))]
    pub code: String,

    pub data: T,

    #[validate(constant("OK"))]
    pub message: String,
}

#[derive(Debug, ApiModel, Serialize, Deserialize)]
pub struct Empty;

#[derive(Debug, ApiModel, Serialize, Deserialize)]
pub enum SseEvent<T> {
    Open,
    Message(SseMessage<T>),
}

#[derive(Debug, ApiModel, Serialize, Deserialize)]
pub struct SseMessage<T> {
    pub event: String,
    pub data: T,
    pub id: String,
    pub retry: Option<u64>,
}

#[derive(Debug, ApiModel, Serialize, Deserialize)]
pub enum WsMessage<T, C> {
    Text(T),

    Ping,

    Pong,

    Close { code: C, reason: String },
}

pub struct FileContent {
    pub bytes: Bytes,
}

pub struct FileItem {
    pub content: FileContent,
    pub file_name: Option<String>,
    pub content_type: Option<String>,
}
